home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_066 / sendpackets / sendpacket / sendpacket.c < prev   
C/C++ Source or Header  |  1992-05-06  |  3KB  |  111 lines

  1. /* sendpacket.c -                   send packet to dos handler            */
  2. /*                                  Phillip Lindsay - Commodore-Amiga     */
  3.  
  4. #include "exec/types.h"
  5. #include "exec/ports.h"
  6. #include "exec/io.h"
  7. #include "exec/memory.h"
  8. #include "libraries/dos.h"
  9. #include "libraries/dosextens.h"
  10. #include <stdio.h>
  11.  
  12. #ifdef MANX
  13. #include "functions.h"           /* aztec C include */
  14. #endif
  15.  
  16. #define ACTION_SCREEN_MODE 994L  /* The packet type we will be playing with */
  17. #define DOSTRUE         -1L  /* AmigaDos TRUE */
  18. #define MAXARGS              7L  /* limit in packet structure (dosextens.h) */
  19.  
  20. long sendpkt(pid,action,args,nargs)
  21.  
  22. struct MsgPort *pid;    /* process indentifier ... (handlers message port ) */
  23. long action,           /* packet type ... (what you want handler to do )   */
  24.      args[],          /* a pointer to a argument list */
  25.      nargs;          /* number of arguments in list  */
  26. {
  27.   
  28.  struct MsgPort        *replyport;
  29.  struct StandardPacket *packet;
  30.  
  31.  long   count, *pargs, res1; 
  32.  
  33.  if(nargs > MAXARGS) exit(FALSE); 
  34.  
  35.  replyport = (struct MsgPort *) CreatePort(NULL,NULL); /* make reply port */
  36.  if(!replyport) return(NULL);
  37.  
  38.  packet = (struct StandardPacket *) 
  39.    AllocMem((long)sizeof(*packet),MEMF_PUBLIC | MEMF_CLEAR);
  40.  if(!packet) 
  41.    {
  42.     DeletePort(replyport);
  43.     return(NULL);
  44.    }
  45.  
  46.  packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt); /* link packet- */
  47.  packet->sp_Pkt.dp_Link         = &(packet->sp_Msg);        /* to message    */
  48.  packet->sp_Pkt.dp_Port         = replyport;         /* set-up reply port   */
  49.  packet->sp_Pkt.dp_Type         = action;           /* what to do... */
  50.  
  51.  /* move all the arguments to the packet */
  52.  pargs = &(packet->sp_Pkt.dp_Arg1);        /* address of first argument */
  53.  for(count=NULL;count < nargs;count++) 
  54.    pargs[count]=args[count];
  55.  
  56.  PutMsg(pid,packet); /* send packet */
  57.  
  58. #ifdef DEBUG
  59.   kprintf("Waiting for packet...\n"); 
  60. #endif
  61.  
  62.  WaitPort(replyport); /* wait for packet to come back */
  63.  GetMsg(replyport);   /* pull message */
  64.  
  65.  res1 = packet->sp_Pkt.dp_Res1; /* get result */
  66.  
  67. /* all done clean up */
  68.  FreeMem(packet,(long)sizeof(*packet)); 
  69.  DeletePort(replyport); 
  70.  
  71.  return(res1);   
  72.   
  73. }
  74.  
  75. /* end of sendpkt.c */
  76.  
  77.  
  78. /* start of example */
  79.  
  80. #define NARGS    1L                      /* number of arguments */
  81. #define ESC    27L
  82.  
  83. main()
  84. {
  85.  
  86.  struct MsgPort *conid;         /* for process id     */
  87.  long arg[NARGS]                /* array of arguments */
  88.       ,res1;                    /* holds result       */ 
  89.  struct Process *myprocess;     /* me!                */
  90.  UBYTE a_char;                  /* our input          */
  91.  
  92.  myprocess = (struct Process *) FindTask(NULL);     
  93.  
  94.  conid = (struct MsgPort *) myprocess->pr_ConsoleTask; /* get console handler */
  95.  
  96.  arg[0]=DOSTRUE;         /* arg1=TRUE - set RAW mode */      
  97.  res1 = sendpkt(conid,ACTION_SCREEN_MODE,arg,NARGS);
  98.  
  99.  if(!res1) exit(TRUE);  /* error? */
  100.  
  101.  puts("In RAW: mode...type something...press ESC to exit.");
  102.  while((a_char=getchar()) != ESC) putchar(a_char);
  103.  
  104.  arg[0]=FALSE; /* turn RAW mode off */
  105.  res1 = sendpkt(conid,ACTION_SCREEN_MODE,arg,NARGS);
  106.  
  107. }
  108.  
  109.  
  110.  
  111.